package com.beerq.view.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.beerq.R;
import com.beerq.util.BasicHttp;
import com.beerq.util.StringUtil;
import com.beerq.view.BaseActivity;
import com.beerq.view_manager.RegisterAndLoginManager;
import com.beerq.view_manager.ValidateManager;

public class ModifyPasswordActivity extends BaseActivity {

    private ValidateManager mValidateManager;
    private TextView txtPassword;
    private TextView txtConfirmPassword;
    private TextView txtPhoneNo;
    private TextView txtValidate_code;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        statusBarType=0;
        super.onCreate(savedInstanceState);
        hideTopBar();
        setMainContentView(R.layout.activity_modify_password);

        mValidateManager=new ValidateManager(this);
        mValidateManager.bind();


        txtPassword=(TextView)findViewById(R.id.edit_password);
        txtConfirmPassword=(TextView)findViewById(R.id.edit_confirm_password);
        txtPhoneNo=(TextView)findViewById(R.id.edit_phone_number);
        txtValidate_code=(TextView)findViewById(R.id.edit_validate_code);
        setEvent();

    }

    private void setEvent(){
        findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String password=txtPassword.getText().toString();
                if(StringUtil.isEmpty(password)){
                    showToast("密码不能为空");
                    return;
                }

                String confirmPassword=txtConfirmPassword.getText().toString();
                if(StringUtil.isEmpty(confirmPassword)){
                    showToast("确认密码不能为空");
                    return;
                }

                if(!password.equals(confirmPassword)){
                    showToast("密码和确认密码不一致");
                    return;
                }

                if(confirmPassword.length()<7){
                    showToast("密码位数要大于6位");
                    return;
                }


                String phoneNo=txtPhoneNo.getText().toString();
                if(StringUtil.isEmpty(phoneNo)){
                    showToast("手机号码不能为空");
                    return;
                }

                String valideateCode=txtValidate_code.getText().toString();
                if(StringUtil.isEmpty(valideateCode)){
                    showToast("验证码不能为空");
                    return;
                }

                if(!mValidateManager.checkValidateCode(valideateCode)){
                    return;
                }

                RegisterAndLoginManager.modifyPwd(mContext, phoneNo, confirmPassword, valideateCode, new BasicHttp.IMyCallBack() {
                    @Override
                    public void onResponse(String resonseData) {
                        Intent intent=new Intent(mContext,LoginActivity.class);
                        startActivity(intent);
                        finish();
                    }

                    @Override
                    public void onFailure(String resonseData) {

                    }
                });




            }
        });
    }

}
